Although computer systems begin with the hardware components, computer operation requires software that controls the use of the hardware components. Typically handled by the operating system running on the computer, these software elements are called device drivers (sometimes shortened to drivers). The device drivers are typically specific to the hardware component they support. Because accessing a particular hardware component requires cooperation among multiple software drivers, those device drivers are grouped true driver stacks (sometimes shortened to stacks). The drivers in each stack work together, allowing access to the desired hardware component.
FIG. 1 shows software hierarchy 105 of software drivers to access a hard disk. Software hierarchy 105 is typical of hierarchies for accessing a particular hardware component. At the top of hierarchy 105 is the Peripheral Component Interconnect (PCI) bus driver. Below that is the Small Computer System Interface (SCSI) adapter driver. The SCSI adapter includes a SCSI port, onto which is connected the hard disk, which has a disk partition on which data may be stored. For each of the devices in the hierarchy, device drivers are needed to control access to the hardware devices. Below the SCSI adapter driver is the SCSI port driver.
Each device driver may export services specific to that device driver. These services may be used by other drivers in the driver stack or by other programs, such as the operating system. FIG. 2A shows driver stack 205 with three device drivers 210, 215, and 220, each device driver providing a service. Driver 215 is using the service provided by driver 210 (as shown by arrow 225), and driver 220 is using the service provided by driver 215 (as shown by arrow 230).
Each driver needs to know if other drivers are using its services. This information is important in case the driver stack is to be removed (see below). Because their services are being used, drivers 210 and 215 have non-zero reference counts. Note that it is not important for the driver to know who is using its service, only that its service is being used.
Although FIG. 2A shows only children drivers using the services of their immediate parents, this is not a limitation of driver services export. For example, in FIG. 2B, driver 210 in driver stack 205 is shown using the services exported by its “grandchild,” driver 220 (shown by arrow 235).
It may happen that a driver stack, loaded to allow access to a particular hardware component, is no longer required. For example, the hardware component in question may have been removed from the computer system. When a driver stack can be removed from the operating system while the computer is in use, the driver stack is called dynamic. The operating system interrogates each driver in the stack, asking the drivers if they may be removed. Then, if each driver in the stack approves the remove query, the driver stack is removed. (Static driver stacks are also possible, but in a static driver stack, the driver stack may not be removed while the computer is running. The static driver stack can only be “removed” by specifying it not be loaded when the computer is next started.)
FIGS. 3A and 3B show the procedure used to query whether a driver slack may be removed. At block 305, the lowest device in the driver in the stack receives the remove query. At decision point 310, the device checks to see if its services are being used by any other programs. If its services are being used, then at block 315 the device signals the operating system that the driver stack may not be removed. Otherwise, at decision point 320 the device checks to see if it is using any services provided by other devices. If it is, then at block 325 the device stops using the service, and at block 330 the device decrements the reference count of the devices whose services it was using. At decision point 335, the device checks to see if it has a parent device in the driver stack. If it does, then at block 340 the device passes the remove query to its parent device, and the process returns to block 305. Otherwise, the last device in the driver stack has approved the remove query, and at block 345 the device signals the operating system that the driver stack may be removed.
A person skilled in the art will recognize that the procedure of FIGS. 3A and 3B will fail when a parent device uses the services of a child device, as shown in FIG. 2B, because the child device must approve the remove query before the parent device receives notice of the remove query. Referring to FIG. 2B, child driver 220 will note that its services are being used and immediately fail the remove query. Parent driver 210 never has a chance to stop using the services of child driver 220, allowing the remove query to succeed.
The present invention addresses these and other problems associated with the prior art.